package com.example.shopping.Orderitems.mapper;


import com.example.shopping.Orderitems.entity.Orderitems;
import com.example.shopping.Orderitems.entity.Query;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Orderitem {
    //查询所有订单
    @Select("<script>" +
            "select * from orderitems " +
            "<where>" +
            " 1=1"+
            "<if test='query!=null'> and goodsname like #{query}</if>" +
            "<if test='pagenum!=null and pagesize!=null'> LIMIT #{pagenum},#{pagesize}</if>"+
            "</where>"+
            "</script>")
    List<Orderitems> getOrderitemsList(Query query);

    @Select("select count(*) from orderitems")
    int getOrderCount();

    //更具用户id查询订单
    @Select("select  * from orderitems where uid=#{userid}")
    List<Orderitems> getOrderitemsList_userid(@Param("userid")int userid);

    //修改订单状态
    @Update("update orderitems set status=#{status} where id=#{id}")
    int UpdateOrderitemsStatus(@Param("status")int status ,@Param("id")int id);


    //模糊查询
    @Select("SELECT * FROM orderitems WHERE goodsname LIKE #{goodsname} ")
    List<Orderitems> getOrder_1(@Param("goodsname") String goodsname);

    //修改订单(只可以修改商品单价和商品购买数量)
    @Update("update orderitems set price=#{price},quantity=#{quantity} where id=#{id}")
    int UpdateOrderitems(@Param("price") Double price,@Param("quantity") int quantity,@Param("id") int id);

    //添加订单
    @Insert("insert into orderitems(uid,orderid,goodsid,goodsname,iconurl,price,quantity,totalprice,status,paymenttype,postage)" +
            " value(#{uid},#{orderid},#{goodsid},#{goodsname},#{iconurl},#{price},#{quantity}," +
            "#{totalprice},#{status},#{paymenttype},#{postage})")
    int addOrderitems(Orderitems orderitems);

    //删除订单
    @Delete("delete from orderitems where id=#{id}")
    int delOrderitems(@Param("id") int id);
}
